/*
 * MainForm.java
 *
 * Created on 26 ������ 2007, 05:46
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 * Note: This source code is protected under the This software is licensed under the CC-GNU GPL.
 */

package OpenToday.GUI;

import OpenToday.Configuration.OpenTodayConfiguration;
import OpenToday.IManager;
import javax.microedition.lcdui.*;

/**
 *
 * @author Menny Even Danan (c) 2007. Note: This source code is protected under the This software is licensed under the CC-GNU GPL.
 */
public class MainForm extends Form implements IOpenTodayGUI
{
    private static Spacer CreateSpacer()
    {
	return new Spacer(1000, 1);
    }
    
    private static Font getDayFont()
    {
	return Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, OpenTodayConfiguration.getInstance().getTitleFontSize());	   
    }
    
    private static Font getEventFont()
    {
	 return Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, OpenTodayConfiguration.getInstance().getEventFontSize());
     }
    
    private int m_firstLineOffset;
    private final IManager m_manager;
    /** Creates a new instance of MainForm */
    public MainForm(IManager manager)
    {
	super("Open Today");
	super.setTitle(null);
	m_manager = manager;
	m_firstLineOffset = 0;
    }
    
    public void RepaintRequired()
    {
	//nothing to do
    }
    
    public void Clear()
    {
	super.deleteAll();
	Spacer fromTop = new Spacer(1000, m_firstLineOffset);
	super.append(fromTop);
    }

    public void SetFirstLineOffset(int offset)
    {
	m_firstLineOffset = offset;
    }

    public void AddDayLine(String dayString)
    {
	StringItem todayString = new StringItem(null, dayString);
	todayString.setFont(getDayFont());
	todayString.setLayout(StringItem.LAYOUT_LEFT);
	super.append(todayString);
	//spacer for the next appoitment
	super.append(CreateSpacer());
    }

    public void AddLine(String text)
    {
	StringItem line = new StringItem(null, text);
	line.setFont(getEventFont());
	line.setLayout(StringItem.LAYOUT_LEFT);
	super.append(line);
	//spacer for the next appoitment
	super.append(CreateSpacer());
    }

    public void AddErrorLine(String errorString)
    {
	AddLine(errorString);
    }
    
    public void AddEventLine(boolean currentEvent, String eventTime, String eventString)
    {
	String fullEventString = currentEvent? ">":"";
	fullEventString += eventTime + "-" + eventString;
	StringItem line = new StringItem(null, fullEventString);
	line.setFont(getEventFont());
	line.setLayout(StringItem.LAYOUT_LEFT);
	super.append(line);
	//spacer for the next appoitment
	super.append(CreateSpacer());
    }

    public void AddAllDayEventLine(String eventString)
    {
	StringItem line = new StringItem(null, eventString);
	line.setFont(getEventFont());
	line.setLayout(StringItem.LAYOUT_LEFT);
	super.append(line);
	//spacer for the next appoitment
	super.append(CreateSpacer());
    }

    public void AddToDoLine(boolean overdue, boolean completed, String todoString)
    {
	StringItem line = new StringItem(null, todoString);
	line.setFont(getEventFont());
	line.setLayout(StringItem.LAYOUT_LEFT);
	super.append(line);
	//spacer for the next appoitment
	super.append(CreateSpacer());
    }
    
    public Displayable getDisplayable()
    {
	return this;
    }

    public void SetDayColor(int R, int G, int B) 
    {
    }

    public void SetEventColor(int R, int G, int B) 
    {
    }

    public void SetBackgroundColor(int R, int G, int B) 
    {
    }

    public void SetBackgroundImage(String fullImageName) {
    }
}
